import { loginAPI } from '@/api'
import { getToken, removeToken, setToken } from '@/utils/auth'
export default {
  state: {
    token: getToken()
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      setToken(token)
    },
    removeToken(state) {
      state.token = null
      removeToken()
    }
  },
  actions: {
    async login(store, data) {
      store.commit('setToken', await loginAPI(data))
    }
  },
  namespaced: true
}
